<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Config as ConfigModel;

class Index extends BaseController
{
    public function index()
    {
        $config = ConfigModel::get(1);
        $info = array(
			'操作系统'=>PHP_OS,
			'运行环境'=>$_SERVER["SERVER_SOFTWARE"],
			'PHP运行方式'=>php_sapi_name(),
            'PHP版本'=>PHP_VERSION,
            // 'MySQL版本'=>$mysql,
			'ThinkPHP版本'=>THINK_VERSION,
			'上传附件限制'=>ini_get('upload_max_filesize'),
			'执行时间限制'=>ini_get('max_execution_time').'秒',
			'服务器时间'=>date("Y年n月j日 H:i:s"),
			// '北京时间'=>gmdate("Y年n月j日 H:i:s",time()+8*3600),
			'服务器域名'=>$_SERVER['SERVER_NAME'],
            '服务器IP'=>gethostbyname($_SERVER['SERVER_NAME']),
			'剩余空间'=>round((@disk_free_space(".")/(1024*1024)),2).'M',
            //'URL访问模式'=>C('URL_MODEL'),
			);

         if(request()->isPost())
        {
            // if ($system->allowField('system_on')->save(input('post.'))) {                
            //     $this->success('更新成功');
            // } else {
            //     $this->error($system->getError());
            // }

            $result = $config->validate(
                [
                    'appid' => 'require',
                    'appsecret' => 'require',
                    '__token__' => 'token',
                ]
            )->allowField('appid,appsecret')->save(input('post.'));
            if (false === $result) {
                $this->error($system->getError());                
            } else {
                $this->success('更新成功');
            }
        }

        $this->assign('config',$config);
        $this->assign('info',$info);
        return $this->fetch();
    }

    
}